# -*- coding: utf-8 -*-
# 姓名:谚语
# 开发时间:2022/11/12 20:09

from flask_restful import Resource
from flask_restful.reqparse import RequestParser

from comment.modules.funding_not_matched import Funding_not_matched
from financial.resources.transaction.seralizer import AllMatchedPaginateSerializer


class AllMatchedResource(Resource):
    """所有待匹配资金列表 和 所有已匹配资金列表"""
    def get(self):
        rp = RequestParser()
        rp.add_argument('curPage')  # 当前页
        rp.add_argument('perPage')  # 每页数量
        rp.add_argument('type')  # 匹配状态,如果传入的是2,则查询所有的已经匹配列表,未匹配不用传

        args = rp.parse_args()
        cur_page = int(args.get('curPage'))
        per_page = int(args.get('perPage'))
        status = int(args.get('type'))

        if not status:
            # 查询所有未匹配和部分匹配的
            matched_list = Funding_not_matched.query.filter(Funding_not_matched.matchedStatus != 2)
        else:
            # 查询所有完全匹配的
            matched_list = Funding_not_matched.query.filter(Funding_not_matched.matchedStatus == 2)

        # 分页   paginate 做分页
        matched_list = matched_list.paginate(cur_page, per_page, error_out=False)

        # 数据序列化
        data = AllMatchedPaginateSerializer(matched_list).to_dict()

        return {'msg': 'success', 'data': data}
